package org.chengyi.model_shop.mapper;

import org.apache.ibatis.annotations.*;
import org.chengyi.model_shop.entity.Category;
import org.chengyi.model_shop.entity.CategoryDetail;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @Select(("select c.id, c.description, c.name, count(p.category_id) as productCount " +
            "from category c left join product p on c.id = p.category_id " +
            "group by c.id, c.description, c.name"))
    List<CategoryDetail> getCategoryList();
    @Insert("INSERT INTO category (name, description) VALUES (#{name}, #{description})")
    int addCategory(Category category);
    @Delete("DELETE FROM category WHERE id=#{categoryId}")
    int deleteCategory(Integer  categoryId);
    @Select("SELECT * FROM category WHERE id=#{categoryId}")
    boolean getById(Integer categoryId);
    @Update("UPDATE category SET name=#{name}, description=#{description} WHERE id=#{id}")
    int updateCategory(Category category);
}
